package com.lechuang.user.controller;

import cn.hutool.json.JSONUtil;
import com.lechuang.common.result.Result;
import com.lechuang.user.dto.*;
import com.lechuang.user.manager.UserManager;
import com.lechuang.user.vo.UserDetailVo;
import com.lechuang.user.vo.UserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Log4j2
@Tag(name = "用户信息类")
public class UserController {

    @Resource
    private UserManager userManager;



    @Operation(summary = "用户中心-查询用户信息-用这个")
    @PostMapping("/selectById")
    public Result<UserVo> selectById(@RequestBody UserQueryDto  userQueryDto){
        log.info("用户信息查询-----userQueryDto-{}", JSONUtil.toJsonStr(userQueryDto));
        UserVo userVo = userManager.selectById(userQueryDto);
        return Result.success(userVo);
    }


    @Operation(summary = "用户中心-更改用户信息")
    @PostMapping("/updateById")
    public Result updateById(@RequestBody EditUserDto editUserDto){
        log.info("用户信息更改------{}", JSONUtil.toJsonStr(editUserDto));
        userManager.updateById(editUserDto);
        return Result.success();
    }


    @Operation(summary = "用户中心-修改登录密码")
    @PostMapping("/editLoginPwd")
    public Result editLoginPwd(@RequestHeader String token ,@RequestBody EditLoginPwdDto editLoginPwdDto){
        log.info("用户修改登录密码------token:{} ,editLoginDto:{}",token, JSONUtil.toJsonStr(editLoginPwdDto));
        userManager.editLoginPwd(token,editLoginPwdDto);
        return Result.success();
    }

    @Operation(summary = "用户中心-修改支付密码")
    @PostMapping("/editPayPwd")
    public Result editPayPwd(@RequestBody EditPayPwdDto editPayPwdDto){
        log.info("用户修改支付密码------editPayPwdDto:{}", JSONUtil.toJsonStr(editPayPwdDto));
        userManager.editPayPwd(editPayPwdDto);
        return Result.success();
    }

    @Operation(summary = "用户中心-更新银行卡")
    @PostMapping("/editBankInfo")
    public Result editBankInfo(@RequestBody EditUserDto editUserDto){
        log.info("更新银行卡------editUserDto:{}", JSONUtil.toJsonStr(editUserDto));
        userManager.editBankInfo(editUserDto);
        return Result.success();
    }

    @Operation(summary = "用户中心-认证")
    @PostMapping("/userAuth")
    public Result userAuth(@RequestBody UserAuthDto userAuthDto){
        log.info("用户中心认证------userAuthDto:{}", JSONUtil.toJsonStr(userAuthDto));
        userManager.userAuth(userAuthDto);
        return Result.success();
    }

}
